package com.StarStudio.Controller;

import com.StarStudio.Domain.HttpStatusCode;
import com.StarStudio.Domain.MessageConstant;
import com.StarStudio.Domain.Meteorology;
import com.StarStudio.Domain.Result;
import com.StarStudio.Service.MeteorologyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/metes")
public class MeteorologyController {

    @Autowired
    private MeteorologyService meteorologyService;

    @GetMapping("/{zoneId}")
    public Result getAllByZoneId(@PathVariable int zoneId){
        List<Meteorology> meteorologyList = null;
        try {
            meteorologyList = meteorologyService.getAllByZoneId(zoneId);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(HttpStatusCode.ERROR, MessageConstant.METEOROLOGY_QUERY_FAIL);
        }
        return new Result(HttpStatusCode.SUCCESS, MessageConstant.METEOROLOGY_QUERY_SUCCESS, meteorologyList);
    }

    @GetMapping("/one/{zoneId}")
    public Result getOneByZoneId(@PathVariable int zoneId){
        Meteorology NewestOneByZoneId = null;
        try {
            NewestOneByZoneId = meteorologyService.getOneByZoneId(zoneId);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(HttpStatusCode.ERROR, MessageConstant.METEOROLOGY_QUERY_FAIL);
        }
        return new Result(HttpStatusCode.SUCCESS, MessageConstant.METEOROLOGY_QUERY_SUCCESS, NewestOneByZoneId);
    }

//    @PostMapping
//    public Result add(@RequestBody Meteorology meteorology) {
//
//    }
//
//    @PutMapping
//    public Result update(@RequestBody Meteorology meteorology){
//        boolean code = meteorologyService.update(meteorology);
//        return new Result(code);
//    }
//
//    @DeleteMapping("{meteorologyId}")
//    public Result delete(@PathVariable Integer meteorologyId){
//        boolean code = meteorologyService.delete(meteorologyId);
//        return new Result(code);
//    }
}
